package com.ruoyi.factory.estimate.service.impl;

import cn.hutool.core.date.DateTime;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.factory.common.utils.IdGen;
import com.ruoyi.factory.estimate.domain.*;
import com.ruoyi.factory.estimate.mapper.*;
import com.ruoyi.factory.estimate.service.EstimateHandleService;
import com.ruoyi.factory.estimate.utils.SignHelper;
import com.ruoyi.factory.qylock.utils.OkHttpUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;


/**
 * @author: LiuJiaji
 * @date: 2025/7/25 08:32
 * @description: TODO 发送待办消息
 * @param:
 * @return:
 **/
@Service
public class EstimateHandleServiceImpl implements EstimateHandleService {
    protected final Logger logger = LoggerFactory.getLogger(EstimateHandleServiceImpl.class);

    private String appid = "2321056247389356037";

    @Autowired
    private PjpsndocinfoMapper pjpsndocinfoMapper;

    @Autowired
    private EstimaterelationMapper estimaterelationMapper;

    @Autowired
    private PjrecordMapper pjrecordMapper;

    @Autowired
    private DeptCustomerMapper deptCustomerMapper;

    @Autowired
    private AppointRelationMapper appointRelationMapper;

    //360待办推送状态 Y推送 N不推送
    @Value("${estimate.enable}")
    private String dbtsenable;

    public AjaxResult sendCommission(String param){
        //待办消息管理
        // 根据部门 查询评价关系 筛选出4分之1的人进行评价
        JSONObject jsonObject = JSONObject.fromObject(param);
//        JSONObject jsonObject2 = jsonObject.optJSONObject(param);
        JSONArray jsonArray = jsonObject.optJSONArray("deptname");
        if(jsonArray.isEmpty()){
            //根据name查询
            Estimaterelation estimaterelation = new Estimaterelation();
//            estimaterelation.setBy_relation_dept(name);
            List<Estimaterelation> estimaterelations = estimaterelationMapper.selectEstimaterelationList(estimaterelation);
            for (Estimaterelation estimaterelation1 : estimaterelations) {
                String pk_dept = estimaterelation1.getPk_dept();
                //被评人
                String by_relation_name = estimaterelation1.getBy_relation_name();
                //上级
                String superior = estimaterelation1.getSuperior();
                //下级
                String subordinate = estimaterelation1.getSubordinate();
                //平级
                String lateral = estimaterelation1.getLateral();
                //被评价者部门
                String by_relation_dept = estimaterelation1.getBy_relation_dept();
                Calendar instance = Calendar.getInstance();
                int i = instance.get(Calendar.YEAR);
                int i1 = instance.get(Calendar.MONTH)+1;

                if(StringUtils.isNotBlank(by_relation_name)){
                    Pjpsndocinfo pjpsndocinfo = new Pjpsndocinfo();
                    pjpsndocinfo.setDeptid(pk_dept);
                    pjpsndocinfo.setPsndocname(by_relation_name);
                    List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo);
                    if(!pjpsndocinfos.isEmpty()){
                        Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos.get(0);
                        //被评价人友空间id
                        String psndocykjid = pjpsndocinfo1.getPsndocykjid();
                        //上级
                        if(StringUtils.isNotBlank(superior)){
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setPsndocname(superior);
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //发送待办
                                Pjrecord pjrecord = new Pjrecord();
                                pjrecord.setPingjiarenid(psndocykjid1);
                                pjrecord.setBeipingjiarenid(psndocykjid);
                                pjrecord.setPeriodyear(String.valueOf(i));
                                pjrecord.setPeriodmonth(String.valueOf(i1));
                                List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                if(pjrecords.isEmpty()){
                                    pushtobaidan(psndocykjid1,psndocykjid,by_relation_name,by_relation_dept);
                                }

                            }
                        }
                        // 下级
                        if(StringUtils.isNotBlank(subordinate)){
                            String[] split = subordinate.split(",");
                            for (String s : split) {
                                //下级
                                Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                                pjpsndocinfo2.setDeptid(pk_dept);
                                pjpsndocinfo2.setPsndocname(s);
                                List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                                if(!pjpsndocinfos2.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                    String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                    //发送待办
                                    Pjrecord pjrecord = new Pjrecord();
                                    pjrecord.setPingjiarenid(psndocykjid1);
                                    pjrecord.setBeipingjiarenid(psndocykjid);
                                    pjrecord.setPeriodyear(String.valueOf(i));
                                    pjrecord.setPeriodmonth(String.valueOf(i1));
                                    List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                    if(pjrecords.isEmpty()){
                                        // 发送待办
                                        pushtobaidan(psndocykjid1,psndocykjid,by_relation_name, by_relation_dept);
                                    }
                                }
                            }
                        }

                        if(StringUtils.isNotBlank(lateral)){
                            String[] split = lateral.split(",");
                            for (String s : split) {
                                //平级
                                Pjpsndocinfo pjpsndocinfo3 = new Pjpsndocinfo();
                                pjpsndocinfo3.setDeptid(pk_dept);
                                pjpsndocinfo3.setPsndocname(s);
                                List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo3);
                                if(!pjpsndocinfos3.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo2 = pjpsndocinfos3.get(0);
                                    String psndocykjid1 = pjpsndocinfo2.getPsndocykjid();
                                    //发送待办
                                    Pjrecord pjrecord = new Pjrecord();
                                    pjrecord.setPingjiarenid(psndocykjid1);
                                    pjrecord.setBeipingjiarenid(psndocykjid);
                                    pjrecord.setPeriodyear(String.valueOf(i));
                                    pjrecord.setPeriodmonth(String.valueOf(i1));
                                    List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                    if(pjrecords.isEmpty()){
                                        // 发送待办
                                        pushtobaidan(psndocykjid1,psndocykjid,by_relation_name, by_relation_dept);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }else{
            for (Object o : jsonArray) {
                String name = (String)o;
                //根据name查询
                Estimaterelation estimaterelation = new Estimaterelation();
                estimaterelation.setBy_relation_dept(name);
                List<Estimaterelation> estimaterelations = estimaterelationMapper.selectEstimaterelationList(estimaterelation);
                for (Estimaterelation estimaterelation1 : estimaterelations) {
                    String pk_dept = estimaterelation1.getPk_dept();
                    //被评人
                    String by_relation_name = estimaterelation1.getBy_relation_name();
                    //上级
                    String superior = estimaterelation1.getSuperior();
                    //下级
                    String subordinate = estimaterelation1.getSubordinate();
                    //平级
                    String lateral = estimaterelation1.getLateral();
                    String by_relation_dept = estimaterelation1.getBy_relation_dept();
                    Calendar instance = Calendar.getInstance();
                    int i = instance.get(Calendar.YEAR);
                    int i1 = instance.get(Calendar.MONTH)+1;

                    if(StringUtils.isNotBlank(by_relation_name)){
                        Pjpsndocinfo pjpsndocinfo = new Pjpsndocinfo();
                        pjpsndocinfo.setDeptid(pk_dept);
                        pjpsndocinfo.setPsndocname(by_relation_name);
                        List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo);
                        if(!pjpsndocinfos.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos.get(0);
                            //被评价人友空间id
                            String psndocykjid = pjpsndocinfo1.getPsndocykjid();
                            //上级
                            if(StringUtils.isNotBlank(superior)){
                                Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                                pjpsndocinfo2.setPsndocname(superior);
                                List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                                if(!pjpsndocinfos2.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                    String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                    //发送待办
                                    Pjrecord pjrecord = new Pjrecord();
                                    pjrecord.setPingjiarenid(psndocykjid1);
                                    pjrecord.setBeipingjiarenid(psndocykjid);
                                    pjrecord.setPeriodyear(String.valueOf(i));
                                    pjrecord.setPeriodmonth(String.valueOf(i1));
                                    List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                    if(pjrecords.isEmpty()){
                                        pushtobaidan(psndocykjid1,psndocykjid,by_relation_name,by_relation_dept);
                                    }

                                }
                            }
                            // 下级
                            if(StringUtils.isNotBlank(subordinate)){
                                String[] split = subordinate.split(",");
                                for (String s : split) {
                                    //下级
                                    Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                                    pjpsndocinfo2.setDeptid(pk_dept);
                                    pjpsndocinfo2.setPsndocname(s);
                                    List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                                    if(!pjpsndocinfos2.isEmpty()){
                                        Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                        String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                        //发送待办
                                        Pjrecord pjrecord = new Pjrecord();
                                        pjrecord.setPingjiarenid(psndocykjid1);
                                        pjrecord.setBeipingjiarenid(psndocykjid);
                                        pjrecord.setPeriodyear(String.valueOf(i));
                                        pjrecord.setPeriodmonth(String.valueOf(i1));
                                        List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                        if(pjrecords.isEmpty()){
                                            // 发送待办
                                            pushtobaidan(psndocykjid1,psndocykjid,by_relation_name,by_relation_dept);
                                        }
                                    }
                                }
                            }

                            if(StringUtils.isNotBlank(lateral)){
                                String[] split = lateral.split(",");
                                for (String s : split) {
                                    //平级
                                    Pjpsndocinfo pjpsndocinfo3 = new Pjpsndocinfo();
                                    pjpsndocinfo3.setDeptid(pk_dept);
                                    pjpsndocinfo3.setPsndocname(s);
                                    List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo3);
                                    if(!pjpsndocinfos3.isEmpty()){
                                        Pjpsndocinfo pjpsndocinfo2 = pjpsndocinfos3.get(0);
                                        String psndocykjid1 = pjpsndocinfo2.getPsndocykjid();
                                        //发送待办
                                        Pjrecord pjrecord = new Pjrecord();
                                        pjrecord.setPingjiarenid(psndocykjid1);
                                        pjrecord.setBeipingjiarenid(psndocykjid);
                                        pjrecord.setPeriodyear(String.valueOf(i));
                                        pjrecord.setPeriodmonth(String.valueOf(i1));
                                        List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                        if(pjrecords.isEmpty()){
                                            // 发送待办
                                            pushtobaidan(psndocykjid1,psndocykjid,by_relation_name,by_relation_dept);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        return null;
    }



    public AjaxResult sendCommission3(String param){
        //待办消息管理 发送待办消息
        JSONObject jsonObject = JSONObject.fromObject(param);
        Calendar instance = Calendar.getInstance();
        int i = instance.get(Calendar.MONTH)+1;
        int i1 = instance.get(Calendar.YEAR);
        //获取手工指定表
        AppointRelation appparam = new AppointRelation();
        List<AppointRelation> appointRelations = appointRelationMapper.selectAppointRelationList(appparam);
        for (AppointRelation appointRelation : appointRelations) {
            //获取被评价人信息
            String byrelationname = appointRelation.getByrelationname();
            byrelationname = removeChineseSpacesEnhanced(byrelationname);
            String byrelationdept = appointRelation.getByrelationdept();
            byrelationdept = removeChineseSpacesEnhanced(byrelationdept);
//            if(byrelationname.contains("Mark Jonathan Brig")){
//                System.out.println(byrelationname);
//            }
            //根据部门推送防止重复推送
//            String pushdept = jsonObject.optString("dept");
//            if(!pushdept.contains(byrelationdept)) continue;

//            if("黏指剂与酯类油产品线,黏指剂研究室,工业油添加剂研究一室,黏指剂与酯类油产品线运作支持部,工业油添加剂研究二室,黏指剂与酯类油产品线市场部,金属加工液研究室,工业油产品线,金属加工液市场部,工业油产品线市场部".contains(byrelationdept)){
                Pjpsndocinfo pjpsndocinfo = new Pjpsndocinfo();
                pjpsndocinfo.setPsndocname(byrelationname);
                pjpsndocinfo.setDeptname(byrelationdept);
                List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo);
                if(!pjpsndocinfos.isEmpty()){
                    Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos.get(0);
                    String psndocykjid = pjpsndocinfo1.getPsndocykjid();
                    String deptname = pjpsndocinfo1.getDeptname();
                    //获取 有关评价人
                    String superior = appointRelation.getSuperior();
                    if(!StringUtils.isEmpty(superior)){
                        String[] split = superior.split(",");
                        for (String s1 : split) {
                            s1 = s1.replaceAll(" ","");
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setPsndocname(s1);
                            //查询评价人信息
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                if("张勇,张超".contains(s1)){
                                    for (Pjpsndocinfo pjpsndocinfo4 : pjpsndocinfos2) {
                                        String deptname1 = pjpsndocinfo4.getDeptname();
                                        if("综合服务研究室,工业油添加剂研究一室".contains(deptname1)){
                                            pjpsndocinfo3 = pjpsndocinfo4;
                                        }else{
                                            continue;
                                        }
                                    }
                                }
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //发送待办
                                Pjpsndocinfo pjp = new Pjpsndocinfo();
                                pjp.setPsndocykjid(psndocykjid);
                                pjp.setEnable("1");
                                List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                                if(!pjpsndocinfos3.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo4 = pjpsndocinfos3.get(0);
                                    //记录
                                    Pjrecord pjrecord = new Pjrecord();
                                    pjrecord.setPingjiarenid(psndocykjid1);
                                    pjrecord.setBeipingjiarenid(psndocykjid);
                                    pjrecord.setPeriodyear(String.valueOf(i1));
//                                    pjrecord.setPeriodmonth(String.valueOf(i));
                                    List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                    if(!pjrecords.isEmpty() && StringUtils.isEmpty(pjrecords.get(0).getPeriodmonth())){
                                        pushtobaidan(psndocykjid1,psndocykjid,pjpsndocinfo4.getPsndocname(),deptname);
                                    }
                                }
                            }
                        }
                    }
                    String subordinate = appointRelation.getSubordinate();
                    if(!StringUtils.isEmpty(subordinate)){
                        String[] split = subordinate.split(",");
                        for (String s1 : split) {
                            s1 = s1.replaceAll(" ","");
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setPsndocname(s1);
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                if("张勇,张超".contains(s1)){
                                    for (Pjpsndocinfo pjpsndocinfo4 : pjpsndocinfos2) {
                                        String deptname1 = pjpsndocinfo4.getDeptname();
                                        if("综合服务研究室,工业油添加剂研究一室".contains(deptname1)){
                                            pjpsndocinfo3 = pjpsndocinfo4;
                                        }else{
                                            continue;
                                        }
                                    }
                                }
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //发送待办 订单id 编码 平台 平台订单id 平台订单编码 收货人姓名 收货人电话 收货人地址 海绵类型 布套类型 长*宽*高*数量 售价 实收 退款备注 退款金额(全退 部分退 补发) 快递费 海绵材料 布套材料 运输费 人工 场地费 推广费 管理费 税 设备折损
                                Pjpsndocinfo pjp = new Pjpsndocinfo();
                                pjp.setPsndocykjid(psndocykjid);
                                pjp.setEnable("1");
                                List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                                if(!pjpsndocinfos3.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo4 = pjpsndocinfos3.get(0);
                                    //记录
                                    Pjrecord pjrecord = new Pjrecord();
                                    pjrecord.setPingjiarenid(psndocykjid1);
                                    pjrecord.setBeipingjiarenid(psndocykjid);
                                    pjrecord.setPeriodyear(String.valueOf(i1));
//                                    pjrecord.setPeriodmonth(String.valueOf(i));
                                    List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                    if(!pjrecords.isEmpty() && StringUtils.isEmpty(pjrecords.get(0).getPeriodmonth())){
                                        pushtobaidan(psndocykjid1,psndocykjid,pjpsndocinfo4.getPsndocname(),deptname);
                                    }
                                }
                            }
                        }
                    }
                    String lateral = appointRelation.getLateral();
                    if(!StringUtils.isEmpty(lateral)){
                        String[] split = lateral.split(",");
                        for (String s1 : split) {
                            s1 = s1.replaceAll(" ","");
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setPsndocname(s1);
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                if("张勇,张超".contains(s1)){
                                    for (Pjpsndocinfo pjpsndocinfo4 : pjpsndocinfos2) {
                                        String deptname1 = pjpsndocinfo4.getDeptname();
                                        if("综合服务研究室,工业油添加剂研究一室".contains(deptname1)){
                                            pjpsndocinfo3 = pjpsndocinfo4;
                                        }else{
                                            continue;
                                        }
                                    }
                                }
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //发送待办
                                Pjpsndocinfo pjp = new Pjpsndocinfo();
                                pjp.setPsndocykjid(psndocykjid);
                                pjp.setEnable("1");
                                List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                                if(!pjpsndocinfos3.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo4 = pjpsndocinfos3.get(0);
                                    //记录
                                    Pjrecord pjrecord = new Pjrecord();
                                    pjrecord.setPingjiarenid(psndocykjid1);
                                    pjrecord.setBeipingjiarenid(psndocykjid);
                                    pjrecord.setPeriodyear(String.valueOf(i1));
//                                    pjrecord.setPeriodmonth(String.valueOf(i));
                                    List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                    if(!pjrecords.isEmpty() && StringUtils.isEmpty(pjrecords.get(0).getPeriodmonth())){
                                        pushtobaidan(psndocykjid1,psndocykjid,pjpsndocinfo4.getPsndocname(),deptname);
                                    }
                                }
                            }
                        }
                    }
                    String customerper = appointRelation.getCustomerper();
                    if(!StringUtils.isEmpty(customerper)){
                        String[] split = customerper.split(",");
                        for (String s1 : split) {
                            s1 = s1.replaceAll(" ","");
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setPsndocname(s1);
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                if("张勇,张超".contains(s1)){
                                    for (Pjpsndocinfo pjpsndocinfo4 : pjpsndocinfos2) {
                                        String deptname1 = pjpsndocinfo4.getDeptname();
                                        if("综合服务研究室,工业油添加剂研究一室".contains(deptname1)){
                                            pjpsndocinfo3 = pjpsndocinfo4;
                                        }else{
                                            continue;
                                        }
                                    }
                                }
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //发送待办
                                Pjpsndocinfo pjp = new Pjpsndocinfo();
                                pjp.setPsndocykjid(psndocykjid);
                                pjp.setEnable("1");
                                List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                                if(!pjpsndocinfos3.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo4 = pjpsndocinfos3.get(0);
                                    //记录
                                    Pjrecord pjrecord = new Pjrecord();
                                    pjrecord.setPingjiarenid(psndocykjid1);
                                    pjrecord.setBeipingjiarenid(psndocykjid);
                                    pjrecord.setPeriodyear(String.valueOf(i1));
//                                    pjrecord.setPeriodmonth(String.valueOf(i));
                                    List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                    if(!pjrecords.isEmpty() && StringUtils.isEmpty(pjrecords.get(0).getPeriodmonth())){
                                        pushtobaidan(psndocykjid1,psndocykjid,pjpsndocinfo4.getPsndocname(),deptname);
                                    }
                                }
                            }
                        }
                    }
                }
//            }
        }
        return null;
    }

    public AjaxResult sendCommission2(String param){
        //待办消息管理
        // 根据部门 查询评价关系 筛选出4分之1的人进行评价
        JSONObject jsonObject = JSONObject.fromObject(param);
//        JSONObject jsonObject2 = jsonObject.optJSONObject(param);
        JSONArray jsonArray = jsonObject.optJSONArray("deptname");
        //是否手工指定
        String s = jsonObject.optString("shifouzd");
        Calendar instance = Calendar.getInstance();
        int i = instance.get(Calendar.MONTH)+1;
        int i1 = instance.get(Calendar.YEAR);
        if(StringUtils.isNotBlank(s)){
            //获取手工指定表
            AppointRelation appparam = new AppointRelation();
            List<AppointRelation> appointRelations = appointRelationMapper.selectAppointRelationList(appparam);
            for (AppointRelation appointRelation : appointRelations) {
                //获取被评价人信息
                String byrelationname = appointRelation.getByrelationname();
                String byrelationdept = appointRelation.getByrelationdept();
                Pjpsndocinfo pjpsndocinfo = new Pjpsndocinfo();
                pjpsndocinfo.setPsndocname(byrelationname);
                pjpsndocinfo.setDeptname(byrelationdept);
                List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo);
                if(!pjpsndocinfos.isEmpty()){
                    Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos.get(0);
                    String psndocykjid = pjpsndocinfo1.getPsndocykjid();
                    String deptname = pjpsndocinfo1.getDeptname();
                    //获取 有关评价人
                    String superior = appointRelation.getSuperior();
                    if(!StringUtils.isEmpty(superior)){
                        String[] split = superior.split(",");
                        for (String s1 : split) {
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setPsndocname(s1);
                            //查询评价人信息
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //发送待办
                                Pjpsndocinfo pjp = new Pjpsndocinfo();
                                pjp.setPsndocykjid(psndocykjid);
                                pjp.setEnable("1");
                                List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                                if(!pjpsndocinfos3.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo4 = pjpsndocinfos3.get(0);
                                    pushtobaidan(psndocykjid1,psndocykjid,pjpsndocinfo4.getPsndocname(),deptname);
                                }
                            }
                        }
                    }
                    String subordinate = appointRelation.getSubordinate();
                    if(!StringUtils.isEmpty(subordinate)){
                        String[] split = subordinate.split(",");
                        for (String s1 : split) {
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setPsndocname(s1);
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //发送待办
                                Pjpsndocinfo pjp = new Pjpsndocinfo();
                                pjp.setPsndocykjid(psndocykjid);
                                pjp.setEnable("1");
                                List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                                if(!pjpsndocinfos3.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo4 = pjpsndocinfos3.get(0);
                                    pushtobaidan(psndocykjid1,psndocykjid,pjpsndocinfo4.getPsndocname(),deptname);
                                }
                            }
                        }
                    }
                    String lateral = appointRelation.getLateral();
                    if(!StringUtils.isEmpty(lateral)){
                        String[] split = lateral.split(",");
                        for (String s1 : split) {
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setPsndocname(s1);
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //发送待办
                                Pjpsndocinfo pjp = new Pjpsndocinfo();
                                pjp.setPsndocykjid(psndocykjid);
                                pjp.setEnable("1");
                                List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                                if(!pjpsndocinfos3.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo4 = pjpsndocinfos3.get(0);
                                    pushtobaidan(psndocykjid1,psndocykjid,pjpsndocinfo4.getPsndocname(),deptname);
                                }
                            }
                        }
                    }
                    String customerper = appointRelation.getCustomerper();
                    if(!StringUtils.isEmpty(customerper)){
                        String[] split = customerper.split(",");
                        for (String s1 : split) {
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setPsndocname(s1);
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //发送待办
                                Pjpsndocinfo pjp = new Pjpsndocinfo();
                                pjp.setPsndocykjid(psndocykjid);
                                pjp.setEnable("1");
                                List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                                if(!pjpsndocinfos3.isEmpty()){
                                    Pjpsndocinfo pjpsndocinfo4 = pjpsndocinfos3.get(0);
                                    pushtobaidan(psndocykjid1,psndocykjid,pjpsndocinfo4.getPsndocname(),deptname);
                                }
                            }
                        }
                    }
                }
            }
            return null;
        }
        if(jsonArray.isEmpty()){
            List<Pjrecord> pjrecords1 = pjrecordMapper.selectPjrecordgroupbydept();
            for (Pjrecord pjrecord : pjrecords1) {
                //部门
                String bpjrdeptname = pjrecord.getBpjrdeptname();
                //根据部门查询被评人
                Pjrecord pjrecord2 = new Pjrecord();
                pjrecord2.setPeriodyear(String.valueOf(i1));
                pjrecord2.setWhether("D");
                pjrecord2.setBpjrdeptname(bpjrdeptname);
                List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordListbpjr(pjrecord2);
                int size = pjrecords.size();
                //根据月份判断多少
                int res = 1;
                if(i==1){
                    res = size/12;
                }else if(i==2){
                    res = size/11;
                }else if(i==3){
                    res = size/10;
                }else if(i==4){
                    res = size/9;
                }else if(i==5){
                    res = size/8;
                }else if(i==6){
                    res = size/7;
                }else if(i==7){
                    res = size/6;
                }else if(i==8){
                    res = size/5;
                }else if(i==9){
                    res = size/4;
                }else if(i==10){
                    res = size/3;
                }else if(i==11){
                    res = size/2;
                }else if(i==12){
                    res = size;
                }

                for (int i2 = 0; i2 < res; i2++) {
                    //被评价人出来了
                    Pjrecord pjrecord1 = pjrecords.get(i2);
                    //查询评价人
                    Pjrecord pjrecord3 = new Pjrecord();
                    pjrecord3.setPeriodyear(String.valueOf(i1));
                    pjrecord3.setWhether("D");
                    pjrecord3.setBpjrdeptname(bpjrdeptname);
                    pjrecord3.setBeipingjiarenid(pjrecord1.getBeipingjiarenid());
                    List<Pjrecord> pjrecords3 = pjrecordMapper.selectPjrecordListbpjr(pjrecord3);
                    for (Pjrecord pjrecord4 : pjrecords3) {
                        String pingjiarenid = pjrecord4.getPingjiarenid();
                        String beipingjiarenid = pjrecord4.getBeipingjiarenid();
                        //根据评价人查询评价人是否评价超过10次
                        Pjrecord pjrecord5 = new Pjrecord();
                        pjrecord5.setPingjiarenid(pingjiarenid);
                        pjrecord5.setPeriodyear(String.valueOf(i1));
                        pjrecord5.setPeriodmonth(String.valueOf(i));
                        pjrecord5.setWhether("D");
                        //查询
                        List<Pjrecord> pjrecords2 = pjrecordMapper.selectPjrecordListf(pjrecord5);
                        int pp = 10;
                        if(i > 10){
                            pp = 100;
                        }
                        if(pjrecords2.size()<pp){
                            //发送待办
                            Pjpsndocinfo pjp = new Pjpsndocinfo();
                            pjp.setPsndocykjid(beipingjiarenid);
                            pjp.setEnable("1");
                            List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                            if(!pjpsndocinfos.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo = pjpsndocinfos.get(0);
                                pushtobaidan(pingjiarenid,beipingjiarenid,pjpsndocinfo.getPsndocname(),bpjrdeptname);
                            }
                        }
                    }
                }
            }


        }else{
            for (Object o : jsonArray) {
                String dept = (String)o;

                //部门
//                    String bpjrdeptname = pjrecord.getBpjrdeptname();
                //根据部门查询被评人
                Pjrecord pjrecord2 = new Pjrecord();
                pjrecord2.setPeriodyear(String.valueOf(i1));
                pjrecord2.setWhether("D");
                pjrecord2.setBpjrdeptname(dept);
                List<Pjrecord> pjrecords4 = pjrecordMapper.selectPjrecordListbpjr(pjrecord2);
                //随机
                Collections.shuffle(pjrecords4);


                for (Pjrecord pjrecord : pjrecords4) {

//                    for (Pjrecord pjrecord4 : pjrecords3) {
                    String pingjiarenid = pjrecord.getPingjiarenid();
                    String beipingjiarenid = pjrecord.getBeipingjiarenid();
                    //根据评价人查询评价人是否评价超过10次
                    Pjrecord pjrecord5 = new Pjrecord();
                    pjrecord5.setPingjiarenid(pingjiarenid);
                    pjrecord5.setPeriodyear(String.valueOf(i1));
                    pjrecord5.setPeriodmonth(String.valueOf(i));
                    pjrecord5.setWhether("D");
                    //查询
                    List<Pjrecord> pjrecords2 = pjrecordMapper.selectPjrecordListf(pjrecord5);
                    int pp = 10;
                    if(pjrecords2.size()<pp){
                        //发送待办
                        Pjpsndocinfo pjp = new Pjpsndocinfo();
                        pjp.setPsndocykjid(beipingjiarenid);
                        pjp.setEnable("1");
                        List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoList(pjp);
                        if(!pjpsndocinfos.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo = pjpsndocinfos.get(0);
                            pushtobaidan(pingjiarenid,beipingjiarenid,pjpsndocinfo.getPsndocname(),dept);
                        }
                    }
//                    }

                }



//                }
            }
        }

        return null;
    }

    public void pushtobaidan(String pingjiaren,String beipingjiaren,String beipingjiarenname,String deptname){
        Calendar instance = Calendar.getInstance();
        int i = instance.get(Calendar.MONTH)+1;
        int i1 = instance.get(Calendar.YEAR);

        //评价人和被评价人需要在职
        Pjpsndocinfo pjpsndocinfo = new Pjpsndocinfo();
        pjpsndocinfo.setPsndocykjid(pingjiaren);
        List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo);
        Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
        pjpsndocinfo2.setPsndocykjid(beipingjiaren);
        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
        if(!pjpsndocinfos.isEmpty() && !pjpsndocinfos2.isEmpty()){
            String enable = pjpsndocinfos.get(0).getEnable();
            String enable1 = pjpsndocinfos2.get(0).getEnable();
            if(enable.equals("1") && enable1.equals("1")){


        //不能自评
        if(!pingjiaren.equals(beipingjiaren) ){
            //非guozongid推送
            if(!pingjiaren.equals("2aa440cc-9f31-4258-8031-251424c9045e")){

//            if(pingjiaren.equals("3583ebc7-02e4-47e8-bfc5-c374e3f010f3")){

                //调用友空间 查询人员信息  根据人员信息发送待办
                String s2 = "";
                if("Y".equals(dbtsenable)){
                    String token = SignHelper.getToken();
//        if(StringUtils.isEmpty(token)) return new AjaxResult(300,"token验证失败,请联系管理员");
                    String url = "https://c2.yonyoucloud.com/iuap-api-gateway/yonbip/uspace/rest/openapi/idempotent/todo/push";
                    url = url+ "?access_token="+token;
                    JSONObject paramj = new JSONObject();

                    String srcMsgId = "2321056247389356037"+IdGen.uuid()+System.currentTimeMillis();
                    String businessKey = "2321056247389356037"+IdGen.uuid()+System.currentTimeMillis();
                    paramj.put("srcMsgId",srcMsgId);
                    paramj.put("title","评价管理");
                    paramj.put("content","评价内容: 被评价人"+beipingjiarenname);
                    paramj.put("appId",appid);
                    paramj.put("businessKey",businessKey);
                    //评价关系及待办信息关联表  存储的是人的id
                    //移动端地址 被评人 评价人 businesskeyhttp://61.163.50.132/
                    paramj.put("mUrl","http://61.163.50.132:9011"+"?code=${esncode}"+"&pingjiaren="+pingjiaren+"&beipingjiaren="+beipingjiaren+"&businessKey="+businessKey);
                    //电脑端地址
                    paramj.put("webUrl","http://61.163.50.132:9011"+"?code=${esncode}"+"&pingjiaren="+pingjiaren+"&beipingjiaren="+beipingjiaren+"&businessKey="+businessKey);
                    //一级分类id
                    paramj.put("catcode1st","6882ed55bb20be59e4201ef6");
                    JSONArray jsa = new JSONArray();
                    jsa.add(pingjiaren);
                    paramj.put("yyUserIds",jsa);

                    String s = paramj.toString();
                    logger.info("评价管理请求友空间发送待办消息入参: "+s);
                    String s1 = OkHttpUtils.okHttpPost(url, s);
                    logger.info("评价管理请求友空间发送待办消息返参: "+s1);
                    JSONObject jsonObject1 = JSONObject.fromObject(s1);
                    JSONObject jsonObject = jsonObject1.optJSONObject("data");
                    s2 = jsonObject.optString("flag");
                }else{
                    s2 = "0";
                }
                //0成功
                if(StringUtils.isNotBlank(s2) && "0".equals(s2)){
                    Pjrecord pjrecord = new Pjrecord();
                    pjrecord.setPeriodyear(String.valueOf(i1));
                    pjrecord.setPeriodmonth(String.valueOf(i));
                    pjrecord.setBpjrdeptname(deptname);
                    pjrecord.setPingjiarenid(pingjiaren);
                    pjrecord.setBeipingjiarenid(beipingjiaren);
                    pjrecord.setCreat_time(new DateTime());
                    pjrecord.setWhether("D");
                    pjrecordMapper.updatePjrecorddb(pjrecord);
                }



//            }

            }
        }
            }
        }
    }

    public AjaxResult intodaibanper(){
        //根据name查询
        Estimaterelation estimaterelation = new Estimaterelation();
//            estimaterelation.setBy_relation_dept(name);
        List<Estimaterelation> estimaterelations = estimaterelationMapper.selectEstimaterelationList(estimaterelation);
        for (Estimaterelation estimaterelation1 : estimaterelations) {
            String pk_dept = estimaterelation1.getPk_dept();
            //被评人
            String by_relation_name = estimaterelation1.getBy_relation_name();
            //上级
            String superior = estimaterelation1.getSuperior();
            //下级
            String subordinate = estimaterelation1.getSubordinate();
            //平级
            String lateral = estimaterelation1.getLateral();
            //被评价者部门
            String by_relation_dept = estimaterelation1.getBy_relation_dept();

            Calendar instance = Calendar.getInstance();
            int i = instance.get(Calendar.YEAR);
            int i1 = instance.get(Calendar.MONTH)+1;

            if(StringUtils.isNotBlank(by_relation_name)){
                Pjpsndocinfo pjpsndocinfo = new Pjpsndocinfo();
                pjpsndocinfo.setDeptid(pk_dept);
                pjpsndocinfo.setPsndocname(by_relation_name);
                List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo);
                if(!pjpsndocinfos.isEmpty()){
                    Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos.get(0);
                    //被评价人友空间id
                    String psndocykjid = pjpsndocinfo1.getPsndocykjid();
                    //上级
                    if(StringUtils.isNotBlank(superior)){
                        Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                        pjpsndocinfo2.setPsndocname(superior);
                        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                        if(!pjpsndocinfos2.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                            String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                            //新增发送待办记录
                            Pjrecord pjrecord = new Pjrecord();
                            pjrecord.setPingjiarenid(psndocykjid1);
                            pjrecord.setBeipingjiarenid(psndocykjid);
                            pjrecord.setPeriodyear(String.valueOf(i));
//                            pjrecord.setPeriodmonth(String.valueOf(i1));
                            List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                            if(pjrecords.isEmpty()){
                                intodaibanperc(psndocykjid1,psndocykjid,by_relation_dept,"1");
                            }
                        }
                    }
                    // 下级
                    if(StringUtils.isNotBlank(subordinate)){
                        String[] split = subordinate.split(",");
                        for (String trimmed : split) {
                            String s = trimmed.trim();
                            //下级
                            Pjpsndocinfo pjpsndocinfo2 = new Pjpsndocinfo();
                            pjpsndocinfo2.setDeptid(pk_dept);
                            pjpsndocinfo2.setPsndocname(s);
                            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo2);
                            if(!pjpsndocinfos2.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo3 = pjpsndocinfos2.get(0);
                                String psndocykjid1 = pjpsndocinfo3.getPsndocykjid();
                                //新增发送待办记录
                                Pjrecord pjrecord = new Pjrecord();
                                pjrecord.setPingjiarenid(psndocykjid1);
                                pjrecord.setBeipingjiarenid(psndocykjid);
                                pjrecord.setPeriodyear(String.valueOf(i));
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                                List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                if(pjrecords.isEmpty()){
                                    // 新增发送待办记录
                                    intodaibanperc(psndocykjid1,psndocykjid, by_relation_dept,"2");
                                }
                            }
                        }
                    }


                    if(StringUtils.isNotBlank(lateral)){
                        String[] split = lateral.split(",");
                        for (String trimmed : split) {
                            String s = trimmed.trim();
                            //平级
                            Pjpsndocinfo pjpsndocinfo3 = new Pjpsndocinfo();
                            pjpsndocinfo3.setDeptid(pk_dept);
                            pjpsndocinfo3.setPsndocname(s);
                            List<Pjpsndocinfo> pjpsndocinfos3 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo3);
                            if(!pjpsndocinfos3.isEmpty()){
                                Pjpsndocinfo pjpsndocinfo2 = pjpsndocinfos3.get(0);
                                String psndocykjid1 = pjpsndocinfo2.getPsndocykjid();
                                //新增发送待办记录
                                Pjrecord pjrecord = new Pjrecord();
                                pjrecord.setPingjiarenid(psndocykjid1);
                                pjrecord.setBeipingjiarenid(psndocykjid);
                                pjrecord.setPeriodyear(String.valueOf(i));
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                                List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                                if(pjrecords.isEmpty()){
                                    // 新增发送待办记录
                                    intodaibanperc(psndocykjid1,psndocykjid, by_relation_dept,"3");
                                }
                            }
                        }
                    }
                }
            }
        }

        //根据客户关系新增待办记录 部门间评价
        DeptCustomer deptCustomer = new DeptCustomer();
        List<DeptCustomer> deptCustomers = deptCustomerMapper.selectDeptCustomerList(deptCustomer);
        for (DeptCustomer customer : deptCustomers) {
            //被评价部门
            String deptName = customer.getDeptName();
            //评价部门
            String deptCustomerName = customer.getDeptCustomerName();

//            Pjpsndocinfo param = new Pjpsndocinfo();
//            param.setDeptname(deptName);
//            param.setPostname("经理");
//            param.setPostname2("主任");
//            List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoListbybumen(param);
//
//            Pjpsndocinfo param2 = new Pjpsndocinfo();
//            param2.setDeptname(deptCustomerName);
//            param2.setPostname("经理");
//            param2.setPostname2("主任");
//            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoListbybumen(param2);
            List<String> postnames = new ArrayList<>();
            postnames.add("司机");
            postnames.add("餐厅接待");
            postnames.add("保安");
            postnames.add("厨师");
            postnames.add("操作工");
            postnames.add("钳工");
            postnames.add("装卸工");
            postnames.add("电工");
            postnames.add("仪表维护");
            postnames.add("焊工");
            postnames.add("职员（职业病休养）");
            postnames.add("仓管员");
            postnames.add("设备安装");
            postnames.add("司炉工");
            postnames.add("调和");
            postnames.add("仓储叉车工");
            postnames.add("帮厨");
            postnames.add("大厨");
            postnames.add("车间技术员");
            postnames.add("仪表");
            postnames.add("厨师长");
            List<Pjpsndocinfo> pjpsndocinfos = pjpsndocinfoMapper.selectPjpsndocinfoListbygw(postnames,deptName);
            List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoListbygw(postnames,deptCustomerName);

            for (Pjpsndocinfo pjpsndocinfo : pjpsndocinfos) {
                for (Pjpsndocinfo pjpsndocinfo1 : pjpsndocinfos2) {
                    String psndocykjid = pjpsndocinfo.getPsndocykjid();
                    String deptname = pjpsndocinfo.getDeptname();
                    String psndocykjid1 = pjpsndocinfo1.getPsndocykjid();
                    intodaibanperc(psndocykjid1,psndocykjid,deptname,"4");
                }
            }

        }

        //指定评价
        AppointRelation appointRelation = new AppointRelation();
        List<AppointRelation> appointRelations = appointRelationMapper.selectAppointRelationList(appointRelation);
        Calendar instance = Calendar.getInstance();
        int i = instance.get(Calendar.YEAR);
        for (AppointRelation relation : appointRelations) {
            String byrelationname = relation.getByrelationname();
            String byrelationdept = relation.getByrelationdept();
            Pjpsndocinfo pjpsndocinfo3 = new Pjpsndocinfo();
            pjpsndocinfo3.setDeptname(byrelationdept);
            pjpsndocinfo3.setPsndocname(byrelationname);
            List<Pjpsndocinfo> pjpsndocinfos1 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo3);
            if(!pjpsndocinfos1.isEmpty()){
                //被评价人
                Pjpsndocinfo pjpsndocinfo = pjpsndocinfos1.get(0);
                String psndocykjid = pjpsndocinfo.getPsndocykjid();
                String superior = relation.getSuperior();
                if(StringUtils.isNotBlank(superior)){
                    String[] split = superior.split(",");
                    for (String s : split) {
                        Pjpsndocinfo pjpsndocinfo4 = new Pjpsndocinfo();
                        pjpsndocinfo4.setPsndocname(s);
                        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo4);
                        if(!pjpsndocinfos2.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos2.get(0);
                            String psndocykjid1 = pjpsndocinfo1.getPsndocykjid();
                            //新增发送待办记录
                            Pjrecord pjrecord = new Pjrecord();
                            pjrecord.setPingjiarenid(psndocykjid1);
                            pjrecord.setBeipingjiarenid(psndocykjid);
                            pjrecord.setPeriodyear(String.valueOf(i));
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                            List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                            if(pjrecords.isEmpty()){
                                // 新增发送待办记录
                                intodaibanperc(psndocykjid1,psndocykjid, byrelationdept,"1");
                            }
                        }
                    }
                }
                String subordinate = relation.getSubordinate();
                if(StringUtils.isNotBlank(subordinate)){
                    String[] split = subordinate.split(",");
                    for (String s : split) {
                        Pjpsndocinfo pjpsndocinfo4 = new Pjpsndocinfo();
                        pjpsndocinfo4.setPsndocname(s);
                        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo4);
                        if(!pjpsndocinfos2.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos2.get(0);
                            String psndocykjid1 = pjpsndocinfo1.getPsndocykjid();
                            //新增发送待办记录
                            Pjrecord pjrecord = new Pjrecord();
                            pjrecord.setPingjiarenid(psndocykjid1);
                            pjrecord.setBeipingjiarenid(psndocykjid);
                            pjrecord.setPeriodyear(String.valueOf(i));
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                            List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                            if(pjrecords.isEmpty()){
                                // 新增发送待办记录
                                intodaibanperc(psndocykjid1,psndocykjid, byrelationdept,"2");
                            }
                        }
                    }
                }
                String lateral = relation.getLateral();
                if(StringUtils.isNotBlank(lateral)){
                    String[] split = lateral.split(",");
                    for (String s : split) {
                        Pjpsndocinfo pjpsndocinfo4 = new Pjpsndocinfo();
                        pjpsndocinfo4.setPsndocname(s);
                        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo4);
                        if(!pjpsndocinfos2.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos2.get(0);
                            String psndocykjid1 = pjpsndocinfo1.getPsndocykjid();
                            //新增发送待办记录
                            Pjrecord pjrecord = new Pjrecord();
                            pjrecord.setPingjiarenid(psndocykjid1);
                            pjrecord.setBeipingjiarenid(psndocykjid);
                            pjrecord.setPeriodyear(String.valueOf(i));
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                            List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                            if(pjrecords.isEmpty()){
                                // 新增发送待办记录
                                intodaibanperc(psndocykjid1,psndocykjid, byrelationdept,"3");
                            }
                        }
                    }
                }
                String customerper = relation.getCustomerper();
                if(StringUtils.isNotBlank(customerper)){
                    String[] split = customerper.split(",");
                    for (String s : split) {
                        Pjpsndocinfo pjpsndocinfo4 = new Pjpsndocinfo();
                        pjpsndocinfo4.setPsndocname(s);
                        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo4);
                        if(!pjpsndocinfos2.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos2.get(0);
                            String psndocykjid1 = pjpsndocinfo1.getPsndocykjid();
                            //新增发送待办记录
                            Pjrecord pjrecord = new Pjrecord();
                            pjrecord.setPingjiarenid(psndocykjid1);
                            pjrecord.setBeipingjiarenid(psndocykjid);
                            pjrecord.setPeriodyear(String.valueOf(i));
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                            List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                            if(pjrecords.isEmpty()){
                                // 新增发送待办记录
                                intodaibanperc(psndocykjid1,psndocykjid, byrelationdept,"4");
                            }
                        }
                    }
                }
            }
        }

        return null;
    }

    public AjaxResult intodaibanper2(){

        //指定评价
        AppointRelation appointRelation = new AppointRelation();
        List<AppointRelation> appointRelations = appointRelationMapper.selectAppointRelationList(appointRelation);
        Calendar instance = Calendar.getInstance();
        int i = instance.get(Calendar.YEAR);
        for (AppointRelation relation : appointRelations) {
            String byrelationname = relation.getByrelationname();
            String byrelationdept = relation.getByrelationdept();
            Pjpsndocinfo pjpsndocinfo3 = new Pjpsndocinfo();
            pjpsndocinfo3.setDeptname(byrelationdept);
            pjpsndocinfo3.setPsndocname(byrelationname);
            if("史东方".contains(byrelationname)){
                System.out.println(byrelationname);
            }
            String customerper1 = relation.getCustomerper();
            if(StringUtils.isNotBlank(customerper1) && customerper1.contains("史东方")){
                System.out.println(byrelationname);
            }
            List<Pjpsndocinfo> pjpsndocinfos1 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo3);
            if(!pjpsndocinfos1.isEmpty()){
                //被评价人
                Pjpsndocinfo pjpsndocinfo = pjpsndocinfos1.get(0);
                String psndocykjid = pjpsndocinfo.getPsndocykjid();
                //上级
                String superior = relation.getSuperior();
                if(StringUtils.isNotBlank(superior)){
                    String[] split = superior.split(",");
                    for (String s : split) {

                        Pjpsndocinfo pjpsndocinfo4 = new Pjpsndocinfo();
                        pjpsndocinfo4.setPsndocname(s);
                        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo4);
                        if(!pjpsndocinfos2.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos2.get(0);
                            if("张勇,张超".contains(s)){
                                for (Pjpsndocinfo pjpsndocinfo2 : pjpsndocinfos2) {
                                    String deptname = pjpsndocinfo2.getDeptname();
                                    if("综合服务研究室,工业油添加剂研究一室".contains(deptname)){
                                        pjpsndocinfo1 = pjpsndocinfo2;
                                    }else{
                                        continue;
                                    }
                                }
                            }
                            String psndocykjid1 = pjpsndocinfo1.getPsndocykjid();
                            //新增发送待办记录
                            Pjrecord pjrecord = new Pjrecord();
                            pjrecord.setPingjiarenid(psndocykjid1);
                            pjrecord.setBeipingjiarenid(psndocykjid);
                            pjrecord.setPeriodyear(String.valueOf(i));
                            pjrecord.setBpjrdeptname(byrelationdept);
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                            List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                            if(pjrecords.isEmpty()){
                                // 新增发送待办记录
                                intodaibanperc(psndocykjid1,psndocykjid, byrelationdept,"1");
                            }else{
                                pjrecord.setRelation("1");
                                pjrecordMapper.updatePjrecordrelation(pjrecord);
                            }
                        }
                    }
                }
                String subordinate = relation.getSubordinate();
                if(StringUtils.isNotBlank(subordinate)){
                    //下级
                    String[] split = subordinate.split(",");
                    for (String s : split) {
                        Pjpsndocinfo pjpsndocinfo4 = new Pjpsndocinfo();
                        pjpsndocinfo4.setPsndocname(s);
                        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo4);
                        if(!pjpsndocinfos2.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos2.get(0);
                            if("张勇,张超".contains(s)){
                                for (Pjpsndocinfo pjpsndocinfo2 : pjpsndocinfos2) {
                                    String deptname = pjpsndocinfo2.getDeptname();
                                    if("综合服务研究室,工业油添加剂研究一室".contains(deptname)){
                                        pjpsndocinfo1 = pjpsndocinfo2;
                                    }else{
                                        continue;
                                    }
                                }
                            }
                            String psndocykjid1 = pjpsndocinfo1.getPsndocykjid();
                            //新增发送待办记录
                            Pjrecord pjrecord = new Pjrecord();
                            pjrecord.setPingjiarenid(psndocykjid1);
                            pjrecord.setBeipingjiarenid(psndocykjid);
                            pjrecord.setPeriodyear(String.valueOf(i));
                            pjrecord.setBpjrdeptname(byrelationdept);
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                            List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                            if(pjrecords.isEmpty()){
                                // 新增发送待办记录
                                intodaibanperc(psndocykjid1,psndocykjid, byrelationdept,"2");
                            }else{
                                pjrecord.setRelation("2");
                                pjrecordMapper.updatePjrecordrelation(pjrecord);
                            }
                        }
                    }
                }
                String lateral = relation.getLateral();
                if(StringUtils.isNotBlank(lateral)){
                    //平级
                    String[] split = lateral.split(",");
                    for (String s : split) {
                        Pjpsndocinfo pjpsndocinfo4 = new Pjpsndocinfo();
                        pjpsndocinfo4.setPsndocname(s);
                        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo4);
                        if(!pjpsndocinfos2.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos2.get(0);
                            if("张勇,张超".contains(s)){
                                for (Pjpsndocinfo pjpsndocinfo2 : pjpsndocinfos2) {
                                    String deptname = pjpsndocinfo2.getDeptname();
                                    if("综合服务研究室,工业油添加剂研究一室".contains(deptname)){
                                        pjpsndocinfo1 = pjpsndocinfo2;
                                    }else{
                                        continue;
                                    }
                                }
                            }
                            String psndocykjid1 = pjpsndocinfo1.getPsndocykjid();
                            //新增发送待办记录
                            Pjrecord pjrecord = new Pjrecord();
                            pjrecord.setPingjiarenid(psndocykjid1);
                            pjrecord.setBeipingjiarenid(psndocykjid);
                            pjrecord.setPeriodyear(String.valueOf(i));
                            pjrecord.setBpjrdeptname(byrelationdept);
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                            List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                            if(pjrecords.isEmpty()){
                                // 新增发送待办记录
                                intodaibanperc(psndocykjid1,psndocykjid, byrelationdept,"3");
                            }else{
                                pjrecord.setRelation("3");
                                pjrecordMapper.updatePjrecordrelation(pjrecord);
                            }
                        }
                    }
                }
                String customerper = relation.getCustomerper();
                if(StringUtils.isNotBlank(customerper)){
                    //客户
                    String[] split = customerper.split(",");
                    for (String s : split) {
                        Pjpsndocinfo pjpsndocinfo4 = new Pjpsndocinfo();
                        pjpsndocinfo4.setPsndocname(s);
                        List<Pjpsndocinfo> pjpsndocinfos2 = pjpsndocinfoMapper.selectPjpsndocinfoList(pjpsndocinfo4);
                        if(!pjpsndocinfos2.isEmpty()){
                            Pjpsndocinfo pjpsndocinfo1 = pjpsndocinfos2.get(0);
                            String psndocykjid1 = pjpsndocinfo1.getPsndocykjid();
                            //新增发送待办记录
                            Pjrecord pjrecord = new Pjrecord();
                            pjrecord.setPingjiarenid(psndocykjid1);
                            pjrecord.setBeipingjiarenid(psndocykjid);
                            pjrecord.setPeriodyear(String.valueOf(i));
                            pjrecord.setBpjrdeptname(byrelationdept);
//                                pjrecord.setPeriodmonth(String.valueOf(i1));
                            List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                            if(pjrecords.isEmpty()){
                                // 新增发送待办记录
                                intodaibanperc(psndocykjid1,psndocykjid, byrelationdept,"4");
                            }else{
                                pjrecord.setRelation("4");
                                pjrecordMapper.updatePjrecordrelation(pjrecord);
                            }
                        }
                    }
                }
            }
        }

        return null;
    }


    public void intodaibanperc(String pingjiaren,String beipingjiaren,String deptname,String relation){

        if(StringUtils.isNotBlank(pingjiaren) && StringUtils.isNotBlank(beipingjiaren) && StringUtils.isNotBlank(deptname) && !pingjiaren.equals(beipingjiaren) ){
            //非guozongid推送
            if(!pingjiaren.equals("2aa440cc-9f31-4258-8031-251424c9045e")){

                Pjrecord pjrecord = new Pjrecord();
                pjrecord.setPingjiarenid(pingjiaren);
                pjrecord.setBeipingjiarenid(beipingjiaren);
                pjrecord.setBpjrdeptname(deptname);
                Calendar instance = Calendar.getInstance();
                int i = instance.get(Calendar.YEAR);
                int i2 = instance.get(Calendar.MONTH)+1;
                pjrecord.setPeriodyear(String.valueOf(i));
                List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList(pjrecord);
                if(pjrecords.isEmpty()){
                    pjrecord.setWhether("D");
                    pjrecord.setCreat_time(new DateTime());
                    pjrecord.setRelation(relation);
                    pjrecordMapper.insertPjrecord(pjrecord);
                }
            }
        }

    }

    /**
     * @author: LiuJiaji
     * @date: 2025/7/25 14:35
     * @description: TODO 个人信息查询
     * @param:
     * @return:
     **/
    public AjaxResult personInfo(String request){
        JSONObject jsonObject = JSONObject.fromObject(request);
        String pingjiarenid = jsonObject.optString("pingjiarenid");
        String beipingjiarenid = jsonObject.optString("beipingjiarenid");
        //待办消息管理
        //调用友空间 查询人员信息  根据人员信息发送待办
        String token = SignHelper.getToken();
        if(StringUtils.isEmpty(token)) return new AjaxResult(300,"token验证失败,请联系管理员");
        String url = "https://c2.yonyoucloud.com/iuap-api-gateway/yonbip/digitalModel/staffQry/getStaff";
        url = url+ "?access_token="+token;

        JSONObject paramj = new JSONObject();
        JSONArray jsa = new JSONArray();
        jsa.add(pingjiarenid);
        jsa.add(beipingjiarenid);
        paramj.put("userId",jsa);

        String s = paramj.toString();
        logger.info("评价管理请求友空间根据id查询人员信息入参: "+s);
        String s1 = OkHttpUtils.okHttpPost(url, s);
        logger.info("评价管理请求友空间发送根据id查询人员信息返参: "+s1);
        JSONObject jsonObject1 = JSONObject.fromObject(s1);
        JSONObject jsonObject4 = jsonObject1.optJSONObject("data");
        JSONArray jsonArray = jsonObject4.optJSONArray("data");
        JSONObject jsonObject3 = new JSONObject();

        for (Object o : jsonArray) {
            JSONObject jsonObject2 = JSONObject.fromObject(o);
            String userId = jsonObject2.optString("userId");
            String userName = jsonObject2.optString("name");
            if(pingjiarenid.equals(userId)){
                jsonObject3.put("pingjiarenname",userName);
            }else{
                jsonObject3.put("beipingjiarenname",userName);
            }
        }

        return new AjaxResult(200,"success",jsonObject3);
    }

    /**
     * @author: LiuJiaji
     * @date: 2025/7/25 14:35
     * @description: TODO 待办信息处理
     * @param:
     * @return:
     **/
    public AjaxResult consumption(String param){
        JSONObject jsonObject = JSONObject.fromObject(param);
        String businessKey = jsonObject.optString("businessKey");
        String beipingjiarenid = jsonObject.optString("beipingjiarenid");
        String pingjiarenid = jsonObject.optString("pingjiarenid");
        String professional_score = jsonObject.optString("professional_score");
        String selfdriven_score = jsonObject.optString("selfdriven_score");
        String innovation_score = jsonObject.optString("innovation_score");
        String attitude_score = jsonObject.optString("attitude_score");
        String collaboration_score = jsonObject.optString("collaboration_score");
        String strategy_score = jsonObject.optString("strategy_score");
        String leadership_score = jsonObject.optString("leadership_score");
        String total_score = jsonObject.optString("total_score");
        String pingyu = jsonObject.optString("comment");

        Pjrecord pjrecord = new Pjrecord();
        pjrecord.setPingjiarenid(pingjiarenid);
        pjrecord.setBeipingjiarenid(beipingjiarenid);
        pjrecord.setZhuanye(professional_score);
        pjrecord.setZiquli(selfdriven_score);
        pjrecord.setChuangxin(innovation_score);
        pjrecord.setGongzuotaidu(attitude_score);
        pjrecord.setXiezuonengli(collaboration_score);
        pjrecord.setZhanlueshiye(strategy_score);
        pjrecord.setLingdaoli(leadership_score);
        pjrecord.setZongji(total_score);
        pjrecord.setPingyu(pingyu);
        Calendar instance = Calendar.getInstance();
        int i = instance.get(Calendar.YEAR);
        int i2 = instance.get(Calendar.MONTH)+1;
        pjrecord.setPeriodyear(String.valueOf(i));
        pjrecord.setWhether("N");
        int i1 = pjrecordMapper.updatePjrecordyb(pjrecord);
        //待办消息管理
        //调用友空间 查询人员信息  根据人员信息发送待办
        String token = SignHelper.getToken();
        if(StringUtils.isEmpty(token)) return new AjaxResult(300,"token验证失败,请联系管理员");
        String url = "https://c2.yonyoucloud.com/iuap-api-gateway/yonbip/uspace/rest/openapi/idempotent/todo/push/done";
        url = url+ "?access_token="+token;

        //待办转已办
        JSONObject paramj = new JSONObject();

        String srcMsgId = "2321056247389356037"+IdGen.uuid()+System.currentTimeMillis();

        paramj.put("srcMsgId",srcMsgId);
        paramj.put("businessKey",businessKey);
        paramj.put("appId",appid);

        String s = paramj.toString();
        logger.info("评价管理请求友空间待办转已办入参: "+s);
        String s1 = OkHttpUtils.okHttpPost(url, s);
        logger.info("评价管理请求友空间待办转已办返参: "+s1);
        JSONObject jsonObject1 = JSONObject.fromObject(s1);

        //收集并整理信息
        return new AjaxResult(200,"success");
    }



    /**
     * @author: LiuJiaji
     * @date: 2025/7/26 10:43
     * @description: TODO 未评价信息通知 rfsys
     * @param:
     * @return:
     **/
    public AjaxResult persontoykjtz(){
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(date);
        //查询信息1.查询未评价信息 2.发送消息
        Calendar instance = Calendar.getInstance();
        instance.add(Calendar.DATE,-5);
        long timeInMillis = instance.getTimeInMillis();
        DateTime dateTime = new DateTime(timeInMillis);
        Pjrecord pjrecord = new Pjrecord();
        pjrecord.setWhether("N");
        pjrecord.setUpdate_time(dateTime);
        List<Pjrecord> pjrecords = pjrecordMapper.selectPjrecordList2(pjrecord);
        for (Pjrecord pjrecord1 : pjrecords) {
            if("Y".equals(dbtsenable)){
                String token = SignHelper.getToken();
                if(StringUtils.isEmpty(token)) return new AjaxResult(300,"token验证失败,请联系管理员");
                String url = "https://c2.yonyoucloud.com/iuap-api-gateway/yonbip/uspace/rest/openapi/idempotent/work/notify/push";
                url = url+ "?access_token="+token;
                JSONObject paramj = new JSONObject();
                JSONArray jsonArray = new JSONArray();
                jsonArray.add(pjrecord1.getPingjiarenid());
//                String uuid = IdGen.uuid();
                paramj.put("srcMsgId","PINGJIA"+dbtsenable+format+pjrecord1.getPingjiarenid());
                paramj.put("yhtUserIds",jsonArray);
                paramj.put("title","360度评价任务提醒");
                paramj.put("content","温馨提醒：您尚未完成对["+pjrecord1.getBeipingjiarenid()+"]的360度评价。您的反馈对组织人才建设至关重要，一份全面、客观的360度评估，离不开每一位评价人的真诚参与。诚邀您尽快登录系统完成评价，感谢您的支持与贡献！");
                String s = paramj.toString();
                logger.info("评价管理请求友空间消息通知入参: "+s);
                String s1 = OkHttpUtils.okHttpPost(url, s);
                logger.info("评价管理请求友空间消息通知返参: "+s1);
                JSONObject jsonObject1 = JSONObject.fromObject(s1);
            }else{
                System.out.println("测试环境未发送");
            }
        }
        return new AjaxResult(200,"success");
    }

    /**
     * @author: LiuJiaji
     * @date: 2025/7/26 10:43
     * @description: TODO 友空间人员信息同步到 rfsys
     * @param:
     * @return:
     **/
    public AjaxResult personykjtorf(){

        pjpsndocinfoMapper.updateenablestatus();
        for (int i = 1; i < 33; i++) {
            //调用友空间 查询人员信息  根据人员信息发送待办
            String token = SignHelper.getToken();
            if(StringUtils.isEmpty(token)) return new AjaxResult(300,"token验证失败,请联系管理员");
            String url = "https://c2.yonyoucloud.com/iuap-api-gateway/yonbip/digitalModel/staff/list";
            url = url+ "?access_token="+token;
            JSONObject paramj = new JSONObject();

            paramj.put("pageIndex",i);
            paramj.put("pageSize",50);
            paramj.put("enable",1);

            String s = paramj.toString();
            logger.info("评价管理请求友空间获取人员列表入参: "+s);
            String s1 = OkHttpUtils.okHttpPost(url, s);
            logger.info("评价管理请求友空间人员列表返参: "+s1);
            JSONObject jsonObject1 = JSONObject.fromObject(s1);
            JSONObject jsonObject2 = jsonObject1.optJSONObject("data");
            JSONArray jsonArray = jsonObject2.optJSONArray("recordList");
            for (Object o : jsonArray) {
                JSONObject jsonObject = JSONObject.fromObject(o);
                String s2 = jsonObject.optString("code");
                String userId = jsonObject.optString("user_id");
                String enable = jsonObject.optString("enable");
                if(StringUtils.isNotBlank(userId) && StringUtils.isNotBlank(enable)){
                    //根据code查询去修改id
                    Pjpsndocinfo pjpsndocinfo = new Pjpsndocinfo();
                    pjpsndocinfo.setPsndoccode(s2);
                    pjpsndocinfo.setPsndocykjid(userId);
                    pjpsndocinfo.setEnable(enable);
                    pjpsndocinfoMapper.updateykjidbycode(pjpsndocinfo);
                }
            }
        }
        return new AjaxResult(200,"success");
    }

    /**
     * 支持中文数字和字母混合的情况
     */
    public String removeChineseSpacesEnhanced(String input) {
        if (input == null) return null;

        // 扩展字符集，包括中文、数字、字母
        String result = input.replace('　', ' ');

        // 匹配中文上下文中的空格（前后都是中文字符）
        Pattern chineseContext = Pattern.compile("(?<=[\\u4e00-\\u9fa5])\\s+(?=[\\u4e00-\\u9fa5])");

        // 循环处理直到没有变化
        String previous;
        do {
            previous = result;
            result = chineseContext.matcher(result).replaceAll("");
        } while (!result.equals(previous));

        return result;
    }


}
